﻿#include "PlatformProperty.h"

MAPPING_VALUE(sdb::AvailabilitySts, PropertyStatus, PropertyStatus::NotAvailable)
    MAPPING_ITEM(sdb::AvailabilitySts::Active, PropertyStatus::Active)
    MAPPING_ITEM(sdb::AvailabilitySts::NotActive, PropertyStatus::NotActive)
    MAPPING_ITEM(sdb::AvailabilitySts::Error, PropertyStatus::Error)
    MAPPING_ITEM(sdb::AvailabilitySts::NotAvailable, PropertyStatus::NotAvailable)
MAPPING_END

SYSTEM_READ_WRITE_PROPERTY(HVAC_MAX_DEFROST_ON, bool) {
    builder
        .area(VehicleAreaSeat::ROW_1_LEFT | VehicleAreaSeat::ROW_1_RIGHT |
              VehicleAreaSeat::ROW_2_LEFT | VehicleAreaSeat::ROW_2_RIGHT |
              VehicleAreaSeat::ROW_2_CENTER)
        .initValue([]() { return false; })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& lastStatus) {
                sdb::AvailabilitySts availabilitySts =
                    sdb::AvailabilitySts(SIGNAL.getPA_CL_MaxDefrost().availability);
                PropertyStatus status = mappingValue(availabilitySts, PropertyStatus::NotAvailable);
                VHALOG.d("HVAC_MAX_DEFROST_ON zone_all availabilitySts is :%d , status changed to: %d ", availabilitySts,status);
                return status;
            },
            PASignal::PA_CL_MaxDefrost)
        .withValueBySignals(
            []([[maybe_unused]] const bool& last) {
                int data = SIGNAL.getPA_CL_MaxDefrost().data;
                VHALOG.d("HVAC_MAX_DEFROST_ON zone_all value changed to: %d ", data);
                return data == 1 ? true : false;
            },
            PASignal::PA_CL_MaxDefrost)
        .onSetProperty([](const bool& value) {
            VHALOG.d("halOnSetProperty HVAC_MAX_DEFROST_ON : %d", value);
            SIGNAL.setCB_CL_MaxDefrost(value ? sdb::OnOff1::On : sdb::OnOff1::Off);
        });
}
